package com.xmb.wechat.view.qq;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.constraint.Group;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.nil.sdk.utils.DateUtils;
import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.entity.QQWithdrawEntity;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/5/21 09:33
 */
public class QQWithdrawDetailActivity extends BaseActivity {

    @BindView(R2.id.title_bar)
    View      mTitleBar;
    @BindView(R2.id.iv_back)
    ImageView mIvBack;
    @BindView(R2.id.tv_title)
    TextView  mTvTitle;
    @BindView(R2.id.tv_right_title)
    TextView  mTvRightTitle;

    @BindView(R2.id.tv_time_1)
    TextView mTvTime1;
    @BindView(R2.id.tv_time_2)
    TextView mTvTime2;
    @BindView(R2.id.tv_time_3)
    TextView mTvTime3;
    @BindView(R2.id.tv_money)

    TextView mTvMoney;
    @BindView(R2.id.tv_service_charge)
    TextView mTvServiceCharge;
    @BindView(R2.id.tv_real_deduct)
    TextView mTvRealDeduct;

    @BindView(R2.id.tv_bank)
    TextView mTvBank;
    @BindView(R2.id.tv_time)
    TextView mTvTime;
    @BindView(R2.id.tv_order_num)
    TextView mTvOrderNum;

    @BindView(R2.id.gp_processing)
    Group mGpProcessing;
    @BindView(R2.id.gp_finish)
    Group mGpFinish;

    public QQWithdrawDetailActivity() {
        super(R.layout.activity_qq_withdraw_detail);
        isChangeStatusBarTxtColor = false;
    }

    public static void start(Activity activity, QQWithdrawEntity entity) {
        Intent intent = new Intent(activity, QQWithdrawDetailActivity.class);
        intent.putExtra("data", entity);
        activity.startActivity(intent);
    }

    @Override
    protected void initView() {
        QQWithdrawEntity entity = (QQWithdrawEntity) getIntent().getSerializableExtra("data");
        if (entity == null)
            return;
        if (entity.isReceived()) {
            mIvBack.setVisibility(View.VISIBLE);
            mTvRightTitle.setVisibility(View.GONE);
            mTvTitle.setText("交易详情");
            mTvTitle.setTextColor(Color.parseColor("#ffffff"));
            //            changeStatusBarTextColor();
            setStatusBarColor(Color.parseColor("#236698"));
            mTitleBar.setBackgroundColor(Color.parseColor("#3AA9FC"));
            mGpFinish.setVisibility(View.VISIBLE);
            mTvTime.setText(TextUtils.isEmpty(entity.getTime()) ? "" : entity.getTime());
        } else {
            mIvBack.setVisibility(View.GONE);
            mTvRightTitle.setVisibility(View.VISIBLE);
            mTvTitle.setText("提现详情");
            //            changeStatusBarTextColor();
            setStatusBarColor(Color.parseColor("#000000"));
            mTitleBar.setBackgroundColor(Color.parseColor("#f0f0f3"));
            mGpProcessing.setVisibility(View.VISIBLE);
            mTvTime1.setText(TextUtils.isEmpty(entity.getTime()) ? "" : entity.getTime());
            mTvTime2.setText(TextUtils.isEmpty(entity.getTime()) ? "" : entity.getTime());
            mTvTime3.setText(getExpectTime(entity.getTime()));
            mTvServiceCharge.setText(TextUtils.isEmpty(entity.getServiceCharge()) ? "" : entity.getServiceCharge() + "元");
        }
        mTvMoney.setText(TextUtils.isEmpty(entity.getMoney()) ? "" : entity.getMoney() + "元");
        mTvRealDeduct.setText(TextUtils.isEmpty(entity.getRealDeduct()) ? "" : entity.getRealDeduct() + "元");
        mTvBank.setText(TextUtils.isEmpty(entity.getBankCard()) ? "" : entity.getBankCard());
        mTvOrderNum.setText(TextUtils.isEmpty(entity.getOrderNum()) ? "" : entity.getOrderNum());
    }

    private String getExpectTime(String time) {
        if (TextUtils.isEmpty(time))
            return "";
        Date date = DateUtils.getDateByFormat(time, "yyyy-MM-dd HH:mm");
        if (date == null)
            return "";
        long dateTime = date.getTime();
        dateTime += 120 * 60 * 1000;
        return new SimpleDateFormat("yyyy-MM-dd HH:mm").format(dateTime);
    }

    @OnClick(R2.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
